#include "WebRtcTransport.h"
#include "rtp/Packet.h"
#include "rtp/RtpPacket.h"
#include <iostream>

void WebRtcTransport::ProcessNonStunPacketFromWebRtcServer(TransportTuple *tuple, const uint8_t* data, size_t len) {
        ::Transport::DataReceived(len);
		// Check if it's RTCP.
		if (Rtp::Rtcp::Packet::IsRtcp(data, len))
		{
			OnRtcpDataReceived(tuple, data, len);
		}
		// Check if it's RTP.
		if (Rtp::RtpPacket::IsRtp(data, len))
		{
			OnRtpDataReceived(tuple, data, len);
		}
		// Check if it's DTLS.
		// else if (RTC::DtlsTransport::IsDtls(data, len))
		// {
		// 	OnDtlsDataReceived(tuple, data, len);
		// }
		else {
            std::cout << "ignoring received packet of unknown type" << std::endl;
		}
}

inline void WebRtcTransport::OnRtpDataReceived(TransportTuple *tuple, const uint8_t *data, size_t len) {
    //....

    Rtp::RtpPacket *packet = Rtp::RtpPacket::Parse(data, len);
    if (!packet) {
        return;
    }
    ReceiveRtpPacket(packet);
}

inline void  WebRtcTransport::OnRtcpDataReceived(TransportTuple* tuple, const uint8_t *data, size_t len) {
	// ....
	
	Rtp::Rtcp::Packet *packet = Rtp::Rtcp::Packet::Parse(data, len);
	if (!packet) {
		return;
	}
	ReceiveRtcpPacket(packet);
}